﻿using System.Diagnostics;
using System.Threading;
using System.Windows;
using CuteConsole;
using CuteConsole.Common;

namespace CuteConsoleApplication
{
  [DebuggerStepThrough]
  public partial class App
  {
    private ConsoleUI _model;
    private Program _program;
    private readonly ManualResetEvent _mrt = new ManualResetEvent(false);

    protected override void OnStartup(StartupEventArgs e)
    {
      base.OnStartup(e);
      var thread = new Thread(ThreadHandler);
      thread.SetApartmentState(ApartmentState.STA);
      thread.IsBackground = true;
      thread.Start();
      _mrt.WaitOne();
      ((IHeddenMethods)_program).Initialize(_model);
      _program.Main();
    }

    private void ThreadHandler()
    {
      _model = new ConsoleUI();
      _program = new Program();
      _mrt.Set();
      WindowModelHelper.Show(_model, new TypeEntry { IsModal = true, Value = typeof(MainWindow) });
    }
  }
}